package redis

import (
	"context"
	"lion-passport/config"
	"log"

	"github.com/go-redis/redis/v8"
)

var Rdb *redis.Client

func InitRedis() {
	config.LoadRedis()
	log.Println("Initializing Redis client...", config.RedisAddr)
	Rdb = redis.NewClient(&redis.Options{
		Addr: config.RedisAddr,
	})

	ctx := context.Background()

	_, err := Rdb.Ping(ctx).Result()
	if err != nil {
		log.Fatalf("Error connecting to Redis: %v\n", err)
	}
	log.Println("✅ Redis连接成功")
}